package 直连版本;

public class Rule {
    static final private int[] i_shift = {0, 0, 1, 1, 1, 0,-1,-1,-1};
    static final private int[] j_shift = {0,-1,-1, 0, 1, 1, 1, 0,-1};

    public static boolean is_win(int[][] arr,int length,int x,int y){
        //如果想用这个方法进行整个棋盘进行扫明 记得在最开始加一个判断是不是空位置
        for(int off=1;off<=4;++off){
            int part_1=0,part_2 = 0;
            for(int i=x,j=y;i < length && i >= 0 && j < length && j >= 0;i+=i_shift[off],j+=j_shift[off]){
                if (arr[i][j] != arr[x][y])
                    break;
                ++part_1;
            }
            for(int i=x,j=y;i < length && i >= 0 && j < length && j >= 0;i+=i_shift[off+4],j+=j_shift[off+4]){
                if (arr[i][j] != arr[x][y])
                    break;
                ++part_2;
            }
            if (part_1+part_2-1 >= 5)return true;
        }
        return false;
    }

    public static boolean can_Put_it_here(int[][] arr,int x,int y){
        try {
            return arr[x][y] == 0;
        }catch (ArrayIndexOutOfBoundsException e){
            System.out.println("越界:x = " + x + " y = " + y);
            e.printStackTrace();
            return false;
        }
    }
}
